﻿using Md.Api.Entity.DapperModels.MdDB;

namespace Md.Dapper.Repositories;
/// <summary>
/// 仓储基类
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IBaseRep<T>
{
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="model">实体</param>
    /// <returns>int</returns>
    public int Insert(T model);
    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sqlWhere">查询</param>
    /// <param name="model">实体</param>
    /// <returns>int</returns>
    public int Delete(string sqlWhere, object model);
    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="sqlSet">set字段</param>
    /// <param name="sqlWhere">查询</param>
    /// <param name="model">实体</param>
    /// <returns>int</returns>
    public int Update(string sqlSet, string sqlWhere, object model);
    /// <summary>
    /// 查询一条数据
    /// </summary>
    /// <param name="sqlFields">字段</param>
    /// <param name="sqlWhere">查询</param>
    /// <param name="model">实体</param>
    /// <returns>T?</returns>
    public T? QuerySingle(string sqlFields, string sqlWhere, object model);
    /// <summary>
    /// 查询数据
    /// </summary>
    /// <param name="sql">sql字符串</param>
    /// <param name="model">实体对象</param>
    /// <returns>IEnumerable<T></returns>
    public IEnumerable<T> Query(string sql, object model);
    /// <summary>
    /// 查询列表数据
    /// </summary>
    /// <param name="sqlFields">字段</param>
    /// <param name="sqlWhere">查询</param>
    /// <param name="model">实体</param>
    /// <returns>IEnumerable<T></returns>
    public IEnumerable<T> QueryList(string sqlFields, string sqlWhere, object model);
    /// <summary>
    /// 查询分页列表数据
    /// </summary>
    /// <param name="sqlFields">字段</param>
    /// <param name="sqlWhere">查询</param>
    /// <param name="model">实体（匿名类型 new {}）</param>
    /// <param name="pageIndex">当前页</param>
    /// <param name="pageSize">每页条数</param>
    /// <returns>IEnumerable<T></returns>
    public Page<T> QueryPage(string sqlFields, string sqlWhere, object model, int pageIndex, int pageSize);
    /// <summary>
    /// 返回第一行第一列
    /// </summary>
    /// <param name="sqlField">字段(单个字段)</param>
    /// <param name="sqlWhere">查询</param>
    /// <param name="model">实体</param>
    /// <returns>object?</returns>
    public object? Scalar(string sqlField, string sqlWhere, object model);
}

